#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<list>
#include<map>

using namespace std;

list<string> interface_list;		
map<string,string> ipadd_map;


void parse_arp(){
	char buffer[4000];
	FILE *fp = fopen("/proc/net/arp","r");
	if(fp == NULL){
		cerr<<"Error in opening file! Please try again\n";
		//exit(1);
	}
        bzero(buffer,4000);
	int loop_counter = 0;
	while(fgets(buffer,4000,fp)!=NULL){
	loop_counter++;
		if(loop_counter == 1){
			continue;
		}else{
			//Parse buffer here
			int inner_loop = 0;
			char *pch;
			pch = strtok (buffer," ");
			string ipadd;
  			while (pch != NULL)
  			{
				inner_loop++;

				if(inner_loop == 1) // Parse for IPAddress, making the last 8 Bits zero
				{	ipadd.clear();
					ipadd = string(pch);
					ipadd[ipadd.length()-1] = '0';
				}
				
				if(inner_loop == 4)
				{
					string macadd = string(pch);
			
					
					pch = strtok (NULL," ");
					pch = strtok (NULL," ");
					
					string inter = string(pch);
					inter = inter.substr(0,inter.length()-1);
					//push to interface list
					interface_list.push_back(inter);
					
                                        string value = macadd + "," + inter;
					//push to ip address map
					ipadd_map[ipadd] = value;
					break;
				}
			       pch = strtok (NULL, " ");
 		        }	
		}
	
	bzero(buffer,4000);

	}



}

int main(){

parse_arp();

return 0;

}
